<?php
namespace app\index\controller;
use think\Db;

class Article extends Common
{


    public function info()
    {
        $id = $this->request->param('id');
        $info = Db::name('article')->where('a_id',$id)->find();
        Db::name('article')->where('a_id',$id)->setInc('click_nums',1);
		
		$cateInfo = Db::name('cate')->where('id',$info['cate_id'])->field('title,is_hide_time,type,id,parent_id')->find();
        $info['navigation'][] = ['id'=>$cateInfo['id'],'title'=>$cateInfo['title']];
		if(!empty($cateInfo['parent_id'])){
			$parentInfo = Db::name('cate')->where('id',$cateInfo['parent_id'])->field('title,is_hide_time,type,id,parent_id')->find();
			array_unshift($info['navigation'],['id'=>$parentInfo['id'],'title'=>$parentInfo['title']]);
			if(!empty($parentInfo['parent_id'])){
				$rootInfo = Db::name('cate')->where('id',$parentInfo['parent_id'])->field('title,is_hide_time,type,id,parent_id')->find();
				array_unshift($info['navigation'],['id'=>$rootInfo['id'],'title'=>$rootInfo['title']]);
			}
		}
		
        $info['is_hide_time'] = $cateInfo['is_hide_time'];
        $this->assign('info',$info);


        $next_info = Db::name('article')->where('cate_id',$info['cate_id'])
            ->where('a_id','>',$info['a_id'])->find();
        $prev_info = Db::name('article')->where('cate_id',$info['cate_id'])
            ->where('a_id','<',$info['a_id'])->find();
        $this->assign('next_info',$next_info);
        $this->assign('prev_info',$prev_info);
		if($cateInfo['type'] == 2){
			$files = explode(',',$info['files']);
			$files = array_filter($files);
			$this->assign('files', $files);
			
			//dump(nl2br($info['info']));die;
			$canshu = explode('<br />',nl2br($info['info']));
			foreach($canshu as $k=>$v){
				$canshu[$k] = explode('|',$v);
			}
			$this->assign('canshu',$canshu);
			//dump($canshu);die;
			
			$tpl = 'info_pro';
		}else{
			$tpl = 'info';
		}
        return $this->fetch($tpl);

    }

}
